package com.ld.security.shop.crawler.modules.re.crawler.java1234;

import com.ld.security.shop.crawler.modules.re.constant.CrawlerConstant;
import com.ld.security.shop.crawler.modules.re.crawler.BaseCrawler;
import com.ld.security.shop.crawler.modules.re.entity.ReDetails;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

@Component
public class Java1234ReDetailsCrawler extends BaseCrawler<ReDetails> {

    public Java1234ReDetailsCrawler() {
        super( CrawlerConstant.projectCode.java1234);
    }

    @Override
    public ReDetails dataCrawler(String url) {

        ReDetails o = super.dataCrawler(url);
        Document document =  this.parse(o.getContent());
        Element content =  document.select(".blog_content").first();

            o.setContent(content.html());



        Elements ps =  document.select(".blog_lastAndNextPage p");
        for (Element p : ps) {
            String text = p.ownText();
            Element a = p.select("a").first();
            String href="";
            if(a != null){
                href = a.attr("href");
            }

            if (text.indexOf("上一篇") != -1) {
                o.setPreUrl(href);
            } else if (text.indexOf("下一篇") != -1) {
                o.setNextUrl(href);
            }
        }
        return o;
    }
}

